package com.daedalus.File.Formatter;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Author: Kostika Gorica
 * User:   kosta
 * Date:   2/2/13
 * Time:   8:07 PM
 */



public class RenditFile {

    public static void main(String[] args){
        String skedari;
        Scanner s = new Scanner(System.in);
        Scanner in;

        //pyes perdoruesin per skedarin
        System.out.print("Emri i File-it :");
        // e lexoj dhe e ruaj
        skedari = s.next();

        try {			// provoj ta hap skedarin per ta lexuar
            in = new Scanner(new File(skedari));
        } catch (FileNotFoundException e) {			// nese nuk hapet me sukses
            System.out.print("File nuk u gjet");
            return;
        }

        int nrStud = 0, i=0;
        if (in.hasNext()){
            nrStud=in.nextInt();
            in.nextLine();
        }
        String studentet[] = new String[nrStud];
        while (in.hasNext()){
            studentet[i]=in.nextLine();
            i++;
        }

        in.close();		// mbyll filen dhe lexuesin

        for (int j=0; j<studentet.length; j++){
            for (int k=j+1; k<studentet.length; k++){
                if ( (studentet[j].compareTo(studentet[k]))>1){
                    String temp = studentet[j];
                    studentet[j]= studentet[k];
                    studentet[k]=temp;
                }
            }
        }
        Formatter out;
        try {
            out = new Formatter("studRenditur.txt");
        } catch (FileNotFoundException e) {
            System.out.print("File nuk u krijua");
            return;
        }

        for (int j=0; j<studentet.length; j++){
            out.format("%s\n",studentet[j]);
        }
        out.close();
    }
}
